﻿using Microsoft.AspNetCore.Mvc;
using Sx.Utils;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sx.Web.Framework
{
    public class BaseController: Controller
    {
        public JsonResult GetSuccessResult() {
            return GetSuccessResult("操作成功！");
        }

        /// <summary>
        /// 获取成功结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public JsonResult GetSuccessResult(string message)
        {
            return  Json(new { resultCode = ResultCode.Success, info = message });
        }

        /// <summary>
        /// 获取返回结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public JsonResult GetResultData(string code, object data)
        {
            return Json(new { resultCode = code, data = data });
        }
        
        /// <summary>
        /// 获取成功结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public JsonResult GetSuccessResult(object data)
        {
            return  Json(new { resultCode = ResultCode.Success, data = data });
        }
        /// <summary>
        /// 获取返回结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public JsonResult GetSuccessResult(string message, object data)
        {
            return Json(new { resultCode = ResultCode.Success, info = message, data = data });
        }

        /// <summary>
        /// 获取失败结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public JsonResult GetErrorResult()
        {
            return Json( new { resultCode = ResultCode.Error, info = "操作失败！" });
        }
        /// <summary>
        /// 获取失败结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public JsonResult GetErrorResult(string message)
        {
            return  Json(new { resultCode = ResultCode.Error, info = message });
        }

        /// <summary>
        /// 获取失败结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public JsonResult GetErrorResultFormat(string messageformat, params object[] parameters)
        {
            return Json( new { resultCode = ResultCode.Error, info = string.Format(messageformat, parameters) });
        }
        /// <summary>
        /// 获取成功结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public JsonResult GetErrorResult(Exception ex)
        {
            return Json( new { resultCode = ResultCode.Error, info = "操作失败！异常内容：" + ex.Message });
        }
        /// <summary>
        /// 获取返回结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public JsonResult GetResultMsg(string code, string message)
        {
            return Json( new { resultCode = code, info = message });
        }

        /// <summary>
        /// 获取返回结果
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public JsonResult GetResultObj(string code, string message, object data)
        {
            return  Json(new { resultCode = code, info = message, data = data });
        }
    }
}
